package callpeople;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class CallPeople1 {
    //点名器
    public static void main(String[] args) {
        //创建容器
        ArrayList<String> list = new ArrayList<>();
        //存放人
        Collections.addAll(list, "徐瑞琪", "朱思衡", "应勋韬", "尹杰", "张航", "朱鹏");
        //方式一
        callpeople1(list);
        //方式二
        callpeople2(list);
    }

    private static void callpeople2(ArrayList<String> list) {
        //打乱元素
        Collections.shuffle(list);
        //一直获取某一个索引上的人物名称
        System.out.println(list.get(0));
    }

    private static void callpeople1(ArrayList<String> list) {
        ////随机点名
        //创建随机数对象
        Random r = new Random();
        //记录容器索引
        int index = r.nextInt(list.size());
        //利用索引返回人物姓名
        String name = list.get(index);
        //打印人物姓名
        System.out.println(name);
    }
}
